import datetime

# 获取当前时间
print(datetime.datetime.now())

# 获取当前日期
print(datetime.datetime.now().date())

# 获取当前时间tuple
print(datetime.datetime.now().timetuple())

# 时间移动（几天、几小时前后...）
print(datetime.datetime.now() + datetime.timedelta(days=1))
print(datetime.datetime.now() + datetime.timedelta(hours=-1))
print(datetime.datetime.now() + datetime.timedelta(minutes=10))

# 时间转化
# 时间转字符串
print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
# 字符串转时间
print(datetime.datetime.strptime('2021-01-01 00:00:00', '%Y-%m-%d %H:%M:%S'))
print(datetime.datetime.strptime('2021年01-01 00:00:00', '%Y年%m-%d %H:%M:%S'))
